import { drizzle } from 'drizzle-orm/mysql2';
import mysql from 'mysql2/promise';

import { appReleaseLog } from './db/schema';

async function main(): Promise<void> {
  await operateOnDatabase();
  process.exit(0);
}

/**
 * Example of how to query the database
 */
async function operateOnDatabase(): Promise<void> {
  const conn = await mysql.createConnection({
    uri: 'mysql://dev-user:dev-user@localhost:3306/spring_boot_dev',
  });

  const db = drizzle(conn);

  const query = db
    .select({
      id: appReleaseLog.id,
      appVersion: appReleaseLog.appVersion,
    })
    .from(appReleaseLog)
    .limit(10);

  console.log(query.toSQL());
}

main().catch((error) => {
  console.error('An error occurred:', error);
  process.exit(1);
});
